<template>
  <a-button type="primary" @click="showModal">指定人员</a-button>
  <a-modal :footer="null" v-model:open="open" title="用户列表" @ok="handleOk">
    <a-table
        :row-selection="rowSelection"
        :columns="columns"
        :data-source="data"
    />
  </a-modal>
</template>

<script setup lang="ts">
import {ref,reactive,computed} from 'vue';
import TableListItem = API.EventList;
import DeptEntity = API.DeptEntity;
import UserEntity = API.UserEntity;
import {Api} from "@/api";

const {eventItem,deptItem} = defineProps({
  eventItem: {
    type: Object as PropType<TableListItem>,
  },
  deptItem: {
    type: Object as PropType<DeptEntity>,
  }
});


const open = ref<boolean>(false);
const data =ref<UserEntity>()



const showModal = async () => {
  console.log(eventItem,deptItem)
  open.value = true;
  const deptUser = await Api.systemUser.userList({deptId: deptItem.id,});
  let records = deptUser.records;
  data.value = records
  console.log(records)
};

const handleOk = (e: MouseEvent) => {
  console.log(e);
  open.value = false;
};

const columns = [
  {
    title: '名称',
    dataIndex: 'username',
  },
  {
    title: '手机号',
    dataIndex: 'phone',
  }
];
const state = reactive<{
  selectedRowKeys: UserEntity[];
  loading: boolean;
}>({
  selectedRowKeys: [],
  loading: false,
});


const rowSelection = ref({
  selectedRowKeys: [],
  checkStrictly: false,
  hideSelectAll: true,
  onChange: (selectedRowKeys: (string | number)[], selectedRows: DeptEntity[]) => {
    console.log('onChange')
    console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
    rowSelection.value.selectedRowKeys = selectedRowKeys as string[]
  },
  onSelect: (record: DeptEntity, selected: boolean, selectedRows: DeptEntity[]) => {
    console.log('onSelect')
    console.log(record, selected, selectedRows);
  },
  onSelectAll: (selected: boolean, selectedRows: DeptEntity[], changeRows: DeptEntity[]) => {
    console.log('onSelectAll')
    console.log(selected, selectedRows, changeRows);
  },
});
</script>

<style></style>
